package weaver.interfaces.holyview.duss.action;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import weaver.conn.RecordSet;
import weaver.interfaces.holyview.duss.util.InvokeHelper;
import weaver.interfaces.schedule.BaseCronJob;

/**
 * @Title: ecology
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-10-30
 * @Description: 定时同步金蝶物料编码
 * @ModifyLog:
 **/

public class WeaMaterialCodeCronJob extends BaseCronJob {
    @Override
    public void execute() {
        RecordSet recordSet = new RecordSet();
        JSONObject params = new JSONObject();
        params.put( "FormId", "BD_MATERIAL" );
        params.put( "FieldKeys", "FName,FNumber" );
        params.put( "FilterString", "" );
        params.put( "OrderString", "" );
        params.put( "TopRowCount", 0 );
        params.put( "TopRowCount", 0 );
        params.put( "StartRow", 0 );
        params.put( "Limit", 0 );
        String result = InvokeHelper.Query("", params.toJSONString() );
        JSONArray objects = JSONObject.parseArray(result);
        for (int i = 0; i < objects.size(); i++) {
            JSONArray arr = (JSONArray) objects.get(i);
            String wlmc = (String) arr.get(0);
            String wlbm = (String) arr.get(1);
            String ggxh = (String) arr.get(2);
            recordSet.executeQuery("select wlbm from uf_wlk where wlbm=?", wlbm);
            if (recordSet.next()) {
                recordSet.executeUpdate("update uf_wlk set wlmc=?,ggxh=? where wlbm=?",wlmc,ggxh,wlbm);
            } else {
                recordSet.executeUpdate("insert into  uf_wlk(wlbm,wlmc,ggxh) values(?,?,?) ", wlbm, wlmc, ggxh);
            }
        }


        System.out.println(result);
    }

    public static void main(String[] args) {
        JSONObject params = new JSONObject();
        params.put( "FormId", "BD_MATERIAL" );
        params.put( "FieldKeys", "FName,FNumber,FSpecification  " );
        params.put( "FilterString", "" );
        params.put( "OrderString", "" );
        params.put( "TopRowCount", 0 );
        params.put( "TopRowCount", 0 );
        params.put( "StartRow", 0 );
        params.put( "Limit", 0 );
        String result = InvokeHelper.Query("", params.toJSONString() );
        JSONArray objects = JSONObject.parseArray(result);
        JSONArray o = (JSONArray) objects.get(2);
        System.out.println(o);

    }
}
